import java.awt.BorderLayout;
import java.awt.Graphics;
import java.awt.GridLayout;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;

import javax.swing.ImageIcon;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

public class SwingReading extends JFrame {
	private JFrame window;
	private String fileStr;
	private static JTextArea area;
	private JScrollPane sp;
	private static JLabel l;
	
	private int n;

	public SwingReading() {
		frame();
		raceChoice();
	}
	
	

	public void Taco(){
		
	}
	public void frame() {
		JFrame window = new JFrame("SC2 Build Orders: Shexy shweet shtuff yo");
		window.setLayout(new GridLayout(2, 1));
		window.setSize(500, 700);
		window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		area = new JTextArea(6, 20);
		area.setLineWrap(true);
		area.setWrapStyleWord(true);
		sp = new JScrollPane(area);
		area.setEditable(false);
		window.add(sp);
		l = new JLabel();
		window.add(l);
		window.setVisible(true);
	}

	public void raceChoice() {

		Object[] options = { "ZERG", "TERRAN", "PROTOSS" };

		n = JOptionPane.showOptionDialog(window, "Race: ", "SC2Builds",
				JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.QUESTION_MESSAGE,
				null, options, options[2]);

		if (n == 0) {
			bZ();

		} else if (n == 1) {
			bT();

		} else {
			bP();
		}

	}

	public void bZ() {
		JDialog.setDefaultLookAndFeelDecorated(true);
		// zerg builds
		Object[] selectionValues = { "14/14", "Stephano's 11 min max", "14/16" };
		String initialSelection = "Select Build";
		Object selection = JOptionPane.showInputDialog(null, "Which Build?",
				"Build Order", JOptionPane.QUESTION_MESSAGE, null,
				selectionValues, initialSelection);

		System.out.println(selection.toString());
		if (selection.equals("14/14")) {
			try {
				BufferedReader br = new BufferedReader(new FileReader(
						"1414.txt"));
				String wholeStr = "";
				String sCurrentLine;

				while ((sCurrentLine = br.readLine()) != null) {
					System.out.println(sCurrentLine);
					wholeStr += sCurrentLine += "\n";
				}
				area.setText(wholeStr);
				ImageIcon icon = new ImageIcon("zerg.jpg");
				l.setIcon(icon);
			} catch (IOException e) {
				e.printStackTrace();
			}
		} else if (selection.equals("Stephano's 11 min max")) {
			System.out.println("Here!");
			try {
				BufferedReader br = new BufferedReader(new FileReader(
						"11minR.txt"));
				System.out.println(br.toString());
				String wholeStr = "";
				String sCurrentLine;

				while ((sCurrentLine = br.readLine()) != null) {
					System.out.println(sCurrentLine);
					wholeStr += sCurrentLine += "\n";
				}

				area.setText(wholeStr);
				area.setText(wholeStr);
				ImageIcon icon = new ImageIcon("zerg.jpg");
				l.setIcon(icon);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (selection.equals("14/16")) {
				try {
					BufferedReader br = new BufferedReader(new FileReader(
							"1416.txt"));
					String wholeStr = "";
					String sCurrentLine;

					while ((sCurrentLine = br.readLine()) != null) {
						System.out.println(sCurrentLine);
						wholeStr += sCurrentLine += "\n";
					}
					area.setText(wholeStr);
					area.setText(wholeStr);
					ImageIcon icon = new ImageIcon("zerg.jpg");
					l.setIcon(icon);
				} catch (IOException e) {
					e.printStackTrace();
				}
			}

		}

	}

	public void bT() {

		JDialog.setDefaultLookAndFeelDecorated(true);
		// terran builds
		Object[] selectionValues = { "1 rax expo", "1/1/1", "FE seige" };
		String initialSelection = "Select Build";
		Object selection = JOptionPane.showInputDialog(null, "Which Build?",
				"Build Order", JOptionPane.QUESTION_MESSAGE, null,
				selectionValues, initialSelection);
		System.out.println(selection.toString());
		if (selection.equals("1 rax expo")) {
			try {
				BufferedReader br = new BufferedReader(
						new FileReader("1rE.txt"));
				String wholeStr = "";
				String sCurrentLine;

				while ((sCurrentLine = br.readLine()) != null) {
					System.out.println(sCurrentLine);
					wholeStr += sCurrentLine += "\n";
				}

				area.setText(wholeStr);
				
				ImageIcon icon = new ImageIcon("terran.jpg");
				l.setIcon(icon);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		if (selection.equals("1/1/1")) {
			try {
				BufferedReader br = new BufferedReader(new FileReader(
						"1-1-1.txt"));
				String wholeStr = "";
				String sCurrentLine;

				while ((sCurrentLine = br.readLine()) != null) {
					System.out.println(sCurrentLine);
					wholeStr += sCurrentLine += "\n";
				}

				area.setText(wholeStr);
				ImageIcon icon = new ImageIcon("terran.jpg");
				l.setIcon(icon);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (selection.equals("FE seige")) {
				try {
					BufferedReader br = new BufferedReader(new FileReader(
							"FEs.txt"));
					String wholeStr = "";
					String sCurrentLine;

					while ((sCurrentLine = br.readLine()) != null) {
						System.out.println(sCurrentLine);
						wholeStr += sCurrentLine += "\n";
					}

					area.setText(wholeStr);
					ImageIcon icon = new ImageIcon("terran.jpg");
					l.setIcon(icon);
				} catch (IOException e) {
					e.printStackTrace();
				}

			}
		}
	}

	private static void bP() {
		JDialog.setDefaultLookAndFeelDecorated(true);
		// Protoss builds

		Object[] selectionValues = { "FFE", "3 gate robo", "DT rush", "Huk's 20 food expo" };
		String initialSelection = "Select Build";
		Object selection = JOptionPane.showInputDialog(null, "Which Build?",
				"Build Order", JOptionPane.QUESTION_MESSAGE, null,
				selectionValues, initialSelection);
		System.out.println(selection.toString());
		if (selection.equals("FFE")) {
			try {
				BufferedReader br = new BufferedReader(new FileReader("FFEp.txt"));
				String wholeStr = "";
				String sCurrentLine;

				while ((sCurrentLine = br.readLine()) != null) {
					System.out.println(sCurrentLine);
					wholeStr += sCurrentLine += "\n";
				}

				area.setText(wholeStr);
				ImageIcon icon = new ImageIcon("protoss.jpg");
				l.setIcon(icon);
			} catch (IOException e) {
				e.printStackTrace();
			}

		}
		if (selection.equals("3 gate robo")) {
			try {
				BufferedReader br = new BufferedReader(new FileReader("3gaterobo.txt"));
				String wholeStr = "";
				String sCurrentLine;

				while ((sCurrentLine = br.readLine()) != null) {
					System.out.println(sCurrentLine);
					wholeStr += sCurrentLine += "\n";
				}

				area.setText(wholeStr);
				ImageIcon icon = new ImageIcon("protoss.jpg");
				l.setIcon(icon);
			} catch (IOException e) {
				e.printStackTrace();
			}

		}
		if (selection.equals("DT rush")) {
			try {
				BufferedReader br = new BufferedReader(new FileReader("DTrush.txt"));
				String wholeStr = "";
				String sCurrentLine;

				while ((sCurrentLine = br.readLine()) != null) {
					System.out.println(sCurrentLine);
					wholeStr += sCurrentLine += "\n";
				}

				area.setText(wholeStr);
				ImageIcon icon = new ImageIcon("protoss.jpg");
				l.setIcon(icon);
			} catch (IOException e) {
				e.printStackTrace();
			}

		}
		if (selection.equals("Huk's 20 food expo")) {
			try {
				BufferedReader br = new BufferedReader(new FileReader("huk20food.txt"));
				String wholeStr = "";
				String sCurrentLine;

				while ((sCurrentLine = br.readLine()) != null) {
					System.out.println(sCurrentLine);
					wholeStr += sCurrentLine += "\n";
				}

				area.setText(wholeStr);
				ImageIcon icon = new ImageIcon("protoss.jpg");
				l.setIcon(icon);
			} catch (IOException e) {
				e.printStackTrace();
			}

	}
	}
}
